package net.begincode.blog.service.impl;

import com.google.common.base.Preconditions;
import net.begincode.blog.dao.HomeTypeMapper;
import net.begincode.blog.entity.HomeType;
import net.begincode.blog.service.HomeTypeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HomeTypeServiceImpl implements HomeTypeService{
    @Resource
    private HomeTypeMapper homeTypeMapper;
    @Override
    public int addHomeType(HomeType homeType) {
        Preconditions.checkNotNull(homeType,"homeType not null");
        return homeTypeMapper.insert(homeType);
    }

    @Override
    public int updateHomeTypeById(HomeType homeType) {
        Preconditions.checkNotNull(homeType,"homeType not null");
        Preconditions.checkArgument(homeType.getId() != null,"homeType id not null");
        return homeTypeMapper.updateByPrimaryKeySelective(homeType);
    }

    @Override
    public List<HomeType> selectByFlag(String flag) {
        Preconditions.checkArgument(StringUtils.isNotEmpty(flag),"flag not empty");
        return homeTypeMapper.selectByFlag(flag);
    }

    @Override
    public HomeType selectById(Long homeTypeId) {
        Preconditions.checkNotNull(homeTypeId,"homeTypeId not null");
        return homeTypeMapper.selectByPrimaryKey(homeTypeId);
    }
}
